package java_collection.lab;

import java.util.Set;
import java.util.TreeSet;

// java FindDups i came i saw i left
// boolean add(E e), return false If this set already contains the element
// TreeSet, which stores its elements in a red-black tree,
// orders its elements based on their values;
// it is substantially slower than HashSet.

public class FindDups3 {

	public static void main(String[] args) {
		String para = "i came i saw i left";
		String[] word = para.split(" ");
		
		Set<String> s = new TreeSet<String>();
        for (String a : word)
            if (!s.add(a))
                System.out.println("Duplicate detected: " + a);

        System.out.println(s.size() + " distinct words: " + s);

	}

}

/*
 * Duplicate detected: i
*  Duplicate detected: i
*  4 distinct words: [came, i, left, saw]
 */
